from django.db import models
from users.models import *
from process.models import FlowModel
# Create your models here.


class BaseModel(models.Model):
    create_time = models.DateTimeField("创建时间", auto_now_add=True, blank=True)
    update_time = models.DateTimeField("更新时间", auto_now=True, blank=True)
    is_delete = models.IntegerField(verbose_name='0是未删除1是删除', default=0)

    class Meta:
        abstract = True


# 模板类型
class Template(BaseModel):
    template_name = models.CharField('模板名称', max_length=32)
    type = models.ForeignKey(FlowModel, on_delete=models.CASCADE, verbose_name='所属流程', null=True, blank=True)

    class Meta:
        db_table = 'tb_template'
        verbose_name = '模板类型'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.template_name


# 请假类型
class Leave_Type(BaseModel):
    type_name = models.CharField('请假类型', max_length=32)
    type = models.ForeignKey(Template, on_delete=models.CASCADE, verbose_name='模板类型')

    class Meta:
        db_table = 'tb_leave_type'
        verbose_name = '请假类型'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.type_name


# 请假模板
class Leave(BaseModel):
    cause = models.CharField('请假原因', max_length=128)
    begin_time = models.DateField(verbose_name='请假日期', blank=True, null=True)
    end_time = models.DateField(verbose_name='归假日期', blank=True, null=True)
    leave_type = models.ForeignKey('Leave_Type', on_delete=models.CASCADE, verbose_name='请假类型', null=True, blank=True)
    type = models.ForeignKey(Template, on_delete=models.CASCADE, verbose_name='模板类型')

    class Meta:
        db_table = 'tb_leave'
        verbose_name = '请假模板'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.cause


# 车型
class Vehicle(BaseModel):
    vehicle_name = models.CharField('车型名', max_length=32)
    type = models.ForeignKey(Template, on_delete=models.CASCADE, verbose_name='模板类型')

    class Meta:
        db_table = 'tb_vehicle'
        verbose_name = '车型'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.vehicle_name


# 车牌
class Plate(BaseModel):
    plate_name = models.CharField('车牌号', max_length=32)
    vehicle = models.ForeignKey('Vehicle', on_delete=models.CASCADE, verbose_name='所属车型')

    class Meta:
        db_table = 'tb_plate'
        verbose_name = '车牌'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.plate_name


# 借款模板
class Money(BaseModel):
    begin_time = models.DateField(verbose_name='借款日期', null=True, blank=True)
    cause = models.CharField('借款原因', max_length=128)
    money = models.IntegerField(verbose_name='借款金额')
    type = models.ForeignKey(Template, on_delete=models.CASCADE, verbose_name='模板类型')

    class Meta:
        db_table = 'tb_money'
        verbose_name = '借款模板'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.cause


# 出差模板
class Travel(BaseModel):
    cause = models.CharField('出差原因', max_length=128)
    begin_time = models.DateField(verbose_name='出差日期', null=True, blank=True)
    end_time = models.DateField(verbose_name='结束日期', null=True, blank=True)
    address = models.CharField('目的地', max_length=32)
    peer = models.CharField('同行人', max_length=8)
    type = models.ForeignKey(Template, on_delete=models.CASCADE, verbose_name='模板类型')

    class Meta:
        db_table = 'tb_travel'
        verbose_name = '出差模板'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.cause


# 转正模板
class Formal(BaseModel):
    begin_time = models.DateField(verbose_name='转正日期', null=True, blank=True)
    cause = models.CharField('自评', max_length=128)
    type = models.ForeignKey(Template, on_delete=models.CASCADE, verbose_name='模板类型')

    class Meta:
        db_table = 'tb_formal'
        verbose_name = '转正模板'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.cause


# 用车模板
class Car(BaseModel):
    begin_time = models.DateField(verbose_name='借车日期', null=True, blank=True)
    end_time = models.DateField(verbose_name='还车日期', null=True, blank=True)
    start = models.CharField('起始地', max_length=32)
    end = models.CharField('目的地', max_length=32)
    vehicle = models.ForeignKey('Vehicle', on_delete=models.CASCADE, verbose_name='车型')
    plate = models.ForeignKey('Plate', on_delete=models.CASCADE, verbose_name='车牌')
    type = models.ForeignKey(Template, on_delete=models.CASCADE, verbose_name='模板类型')

    class Meta:
        db_table = 'tb_car'
        verbose_name = '用车模板'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.start


# 报销模板
class Expense(BaseModel):
    money = models.IntegerField(verbose_name='报销金额')
    cause = models.CharField('报销事由', max_length=256)
    voucher = models.CharField('报销图片', max_length=256)
    type = models.ForeignKey(Template, on_delete=models.CASCADE, verbose_name='模板类型')

    class Meta:
        db_table = 'tb_expense'
        verbose_name = '报销模板'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.cause


class Material(BaseModel):
    materialname = models.CharField(verbose_name="材料名字", max_length=25)
    materialurl = models.CharField(verbose_name="材料地址", max_length=256)

    class Meta:
        db_table = 'tb_material'
        verbose_name = '材料'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.materialname






